//
//  HJPrintSettlementSheetView.m
//  GAMCAfterSales
//
//  Created by 贺佳 on 2018/5/17.
//  Copyright © 2018年 glendale. All rights reserved.
//

#import "HJPrintSettlementSheetView.h"

#import "HJSettlementRepairProjectViewCell.h"
#import "HJSettlementRepairPartsViewCell.h"
#import "HJSettlementAdditionalItemsViewCell.h"

@interface HJPrintSettlementSheetView()<UITableViewDelegate,UITableViewDataSource>
/**
 业务单号
 */
@property(nonatomic,weak)UILabel*numberLabel;
/**
 title
 */
@property(nonatomic,weak)UILabel*titleLabel;
/**
 结算日期
 */
@property(nonatomic,weak)UILabel*settlementTimeLabel;
/**
 维修类型
 */
@property(nonatomic,weak)UILabel*repairTypeLabel;
/**
 送修人
 */
@property(nonatomic,weak)UILabel*sendRepairLabel;
/**
 送修人电话
 */
@property(nonatomic,weak)UILabel*sendRepairPhoneLabel;
/**
 服务顾问
 */
@property(nonatomic,weak)UILabel*serviceAdviserLabel;
/**
 出厂里程
 */
@property(nonatomic,weak)UILabel*mileageLabel;
/**
 vin
 */
@property(nonatomic,weak)UILabel*vinLabel;
/**
 车牌号
 */
@property(nonatomic,weak)UILabel*carNumberLabel;
/**
 车型
 */
@property(nonatomic,weak)UILabel*carTypeLabel;
/**
 维修技师
 */
@property(nonatomic,weak)UILabel*repairTechLabel;
/**
 开工单时间
 */
@property(nonatomic,weak)UILabel*placeOrderLabel;
/**
 竣工时间
 */
@property(nonatomic,weak)UILabel*completedTimeLabel;
/**
 工时费合计
 */
@property(nonatomic,weak)UILabel*projectTotalLabel;
/**
 维修项目工程优惠
 */
@property(nonatomic,weak)UILabel*projectDiscountLabel;
/**
 维修配件费合计
 */
@property(nonatomic,weak)UILabel*repairPartTotalLabel;
/**
 维修配件优惠
 */
@property(nonatomic,weak)UILabel*repairDiscountLabel;
/**
 附加费合计
 */
@property(nonatomic,weak)UILabel*addTotalLabel;
/**
 附加费优惠卷
 */
@property(nonatomic,weak)UILabel*addDiscountLabel;

/**
 费用合计
 */
@property(nonatomic,weak)UILabel*costTotalLabel;
/**
 优惠合计
 */
@property(nonatomic,weak)UILabel*discountTotalLabel;
/**
 圆整金额
 */
@property(nonatomic,weak)UILabel*yuanzhengLabel;
/**
 减免金额
 */
@property(nonatomic,weak)UILabel*jianMianPriceLabel;
/**
 去零金额
 */
@property(nonatomic,weak)UILabel*qulingPriceLabel;
/**
 应收总金额
 */
@property(nonatomic,weak)UILabel*availPriceLabel;
/**
备注
 */
@property(nonatomic,weak)UILabel*remarkLabel2;
/**
 服务热线
 */
@property(nonatomic,weak)UILabel*servicePhoneLabel;
/**
 承修单位
 */
@property(nonatomic,weak)UILabel*companyLabel;
/**
 地址
 */
@property(nonatomic,weak)UILabel*addressLabel;
/**
 维修项目table
 */
@property(nonatomic,weak)UITableView*projectTableView;
/**
 维修配件table
 */
@property(nonatomic,weak)UITableView*repairPartTableView;
/**
 附加项目table
 */
@property(nonatomic,weak)UITableView*otherProjectTableView;
/**
 维修字典
 */
@property(nonatomic,strong)NSMutableDictionary*repairTypeCodeDict;
@end
@implementation HJPrintSettlementSheetView
-(NSMutableDictionary *)repairTypeCodeDict
{
    if (!_repairTypeCodeDict) {
        _repairTypeCodeDict=[NSMutableDictionary dictionary];
        NSArray*ary=[self readershuDICimform][@"TM_REPAIR_TYPE_MAIN"];
        _repairTypeCodeDict=[NSMutableDictionary dictionary];
        for (NSDictionary*dict in ary) {
            _repairTypeCodeDict[dict[@"CODE"]]=dict[@"NAME"];
        }
    }
    return _repairTypeCodeDict;
}
-(NSMutableDictionary *)readershuDICimform
{
    NSMutableDictionary *dic=[NSMutableDictionary dictionary];
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path=[paths objectAtIndex:0];
    NSString *str=[path stringByAppendingPathComponent:@"Dic.text"];
    dic=[NSMutableDictionary dictionaryWithContentsOfFile:str];
    //nslog(@"%@",dic);
    return dic;
}
InitFrameM
-(void)setUI{
    self.backgroundColor=[UIColor whiteColor];
    UIScrollView*scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.mj_w, self.mj_h)];
    self.scrollView=scrollView;
    [self addSubview:scrollView];
    
    //内容视图
    UIView*contentView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.mj_w, self.mj_h)];
    [scrollView addSubview:contentView];
    self.contentView=contentView;
    
    //标题
    UILabel*titleLabel=[[UILabel alloc]init];
    [contentView addSubview:titleLabel];
    titleLabel.font=[UIFont boldSystemFontOfSize:16];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(contentView);
        make.top.mas_equalTo(contentView).offset(30);
    }];
    self.titleLabel=titleLabel;
    
    //子标题
    UILabel*subTitleLabel=[[UILabel alloc]init];
    [contentView addSubview:subTitleLabel];
    subTitleLabel.text=@"维修结算单";
    subTitleLabel.font=[UIFont boldSystemFontOfSize:13];
    [subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(contentView);
        make.top.mas_equalTo(titleLabel.mas_bottom).offset(10);
    }];
    
//    //单编号
    UILabel*order_snLabel=[[UILabel alloc]init];
    [contentView addSubview:order_snLabel];
    
    order_snLabel.font=[UIFont boldSystemFontOfSize:13];
    [order_snLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(subTitleLabel.mas_right).offset(100);
        make.centerY.mas_equalTo(subTitleLabel);
    }];
    self.order_snLabel=order_snLabel;
//
    UILabel*label1=[[UILabel alloc]init];
    [contentView addSubview:label1];
    label1.font=[UIFont boldSystemFontOfSize:13];
    label1.text=@"付费对象:";
    [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(subTitleLabel.mas_bottom).offset(30);
        make.left.mas_equalTo(contentView).offset(20);
    }];

    //业务单号
    UILabel*numberLabel=[[UILabel alloc]init];
    [contentView addSubview:numberLabel];
    numberLabel.text=@"业务单号:";
    self.numberLabel=numberLabel;
    [numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(label1);
        make.top.mas_equalTo(label1.mas_bottom).offset(10);
    }];

    //结算日起
    UILabel*settlementTimeLabel=[[UILabel alloc]init];
    settlementTimeLabel.text=@"结算日期:";
    self.settlementTimeLabel=settlementTimeLabel;
    [contentView addSubview:settlementTimeLabel];
    [settlementTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(numberLabel.mas_right);
        make.size.mas_equalTo(numberLabel);
        make.centerY.mas_equalTo(numberLabel);
    }];
//
    //维修类型
    UILabel*repairTypeLabel=[[UILabel alloc]init];
    [contentView addSubview:repairTypeLabel];
    repairTypeLabel.text=@"维修类型:";
    self.repairTypeLabel=repairTypeLabel;
    [repairTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(settlementTimeLabel.mas_right);
        make.size.mas_equalTo(numberLabel);
        make.centerY.mas_equalTo(numberLabel);
        make.right.mas_equalTo(contentView).inset(20);
    }];
    //送修人
    UILabel*sendRepairLabel=[[UILabel alloc]init];
    [contentView addSubview:sendRepairLabel];
    sendRepairLabel.text=@"送  修  人:";
    self.sendRepairLabel=sendRepairLabel;
    [sendRepairLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.width.mas_equalTo(numberLabel);
        make.top.mas_equalTo(numberLabel.mas_bottom).offset(10);
    }];

    //送修人电话
    UILabel*sendRepairPhoneLabel=[[UILabel alloc]init];
    [contentView addSubview:sendRepairPhoneLabel];
    sendRepairPhoneLabel.text=@"送修人电话:";
    self.sendRepairPhoneLabel=sendRepairPhoneLabel;
    [sendRepairPhoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(settlementTimeLabel);
        make.centerY.mas_equalTo(sendRepairLabel);
    }];

    //服务顾问
    UILabel*serviceAdviserLabel=[[UILabel alloc]init];
    [contentView addSubview:serviceAdviserLabel];
    serviceAdviserLabel.text=@"服务顾问:";
    self.serviceAdviserLabel=serviceAdviserLabel;
    [serviceAdviserLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(repairTypeLabel);
        make.centerY.mas_equalTo(sendRepairLabel);
    }];
//
//    //vin
    UILabel*vinLabel=[[UILabel alloc]init];
    [contentView addSubview:vinLabel];
    vinLabel.text=@"VIN:";
    self.vinLabel=vinLabel;
    [vinLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.width.mas_equalTo(numberLabel);
        make.top.mas_equalTo(sendRepairLabel.mas_bottom).offset(10);
    }];

    //车牌号
    UILabel*carNumberLabel=[[UILabel alloc]init];
    [contentView addSubview:carNumberLabel];
    carNumberLabel.text=@"车  牌  号:";
    self.carNumberLabel=carNumberLabel;
    [carNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(settlementTimeLabel);
        make.centerY.mas_equalTo(vinLabel);
    }];
    //出厂里程
    UILabel*mileageLabel=[[UILabel alloc]init];
    [contentView addSubview:mileageLabel];
    mileageLabel.text=@"出厂里程:";
    self.mileageLabel=mileageLabel;
    [mileageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(repairTypeLabel);
        make.centerY.mas_equalTo(vinLabel);
    }];
//
    //车型
    UILabel*carTypeLabel=[[UILabel alloc]init];
    [contentView addSubview:carTypeLabel];
    carTypeLabel.text=@"车型:";
    self.carTypeLabel=carTypeLabel;
    [carTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(numberLabel);
        make.top.mas_equalTo(vinLabel.mas_bottom).offset(10);
    }];
    //维修技师
    UILabel*repairTechLabel=[[UILabel alloc]init];
    [contentView addSubview:repairTechLabel];
    repairTechLabel.text=@"维修技师:";
    self.repairTechLabel=repairTechLabel;
    [repairTechLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(repairTypeLabel);
        make.centerY.mas_equalTo(carTypeLabel);
    }];

    //开单时间
    UILabel*placeOrderLabel=[[UILabel alloc]init];
    [contentView addSubview:placeOrderLabel];
    placeOrderLabel.text=@"开工单时间:";
    self.placeOrderLabel=placeOrderLabel;
    [placeOrderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.width.mas_equalTo(numberLabel);
        make.top.mas_equalTo(carTypeLabel.mas_bottom).offset(10);
    }];

    //竣工时间
    UILabel*completedTimeLabel=[[UILabel alloc]init];
    [contentView addSubview:completedTimeLabel];
    completedTimeLabel.text=@"竣工时间:";
    self.completedTimeLabel=completedTimeLabel;
    [completedTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(settlementTimeLabel);
        make.centerY.mas_equalTo(placeOrderLabel);
    }];
    
    //维修项目
    UILabel*label2=[[UILabel alloc]init];
    [contentView addSubview:label2];
    label2.font=[UIFont boldSystemFontOfSize:13];
    label2.text=@"维修项目结算";
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(completedTimeLabel.mas_bottom).offset(30);
        make.left.mas_equalTo(label1);
    }];
    //维修项目头部
    NSMutableArray *labelMutabelArray = [[NSMutableArray alloc]initWithObjects:@"序号",@"项目代码",@"项目名称",@"收费区分",@"共时费",@"折扣率",@"优惠金额",@"实收金额", nil];
    HJCommonTableHeaderView*projectHeaderView=[[HJCommonTableHeaderView alloc]init];
    projectHeaderView.titleAry=[labelMutabelArray copy];
    [self addSubview:projectHeaderView];
    [projectHeaderView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(contentView).inset(20);
        make.height.mas_equalTo(45);
        make.top.mas_equalTo(label2.mas_bottom);
    }];
    UITableView*projectTableView=[[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
    projectTableView.delegate=self;
    projectTableView.dataSource=self;
    projectTableView.tableFooterView=[UIView new];
    self.projectTableView=projectTableView;
    projectTableView.layer.borderWidth=1;
    projectTableView.layer.borderColor=[UIColor grayColor].CGColor;
    projectTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    
    [contentView addSubview:projectTableView];
    [projectTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(projectHeaderView);
        make.top.mas_equalTo(projectHeaderView.mas_bottom);
        make.height.mas_equalTo(100);
    }];
    
    //工时合计
    UILabel*projectTotalLabel=[[UILabel alloc]init];
    [contentView addSubview:projectTotalLabel];
    projectTotalLabel.text=@"工时费合计:";
    self.projectTotalLabel=projectTotalLabel;
    [projectTotalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(label1);
        make.top.mas_equalTo(projectTableView.mas_bottom).offset(10);
    }];
    //优惠金额
    UILabel*projectDiscountLabel=[[UILabel alloc]init];
    [contentView addSubview:projectDiscountLabel];
    projectDiscountLabel.text=@"优惠金额:";
    self.projectDiscountLabel=projectDiscountLabel;
    [projectDiscountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(projectTableView);
        make.centerY.mas_equalTo(projectTotalLabel);
    }];
    
    //维修配件项目
    UILabel*label3=[[UILabel alloc]init];
    [contentView addSubview:label3];
    label3.font=[UIFont boldSystemFontOfSize:13];
    label3.text=@"维修配件结算";
    [label3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(projectDiscountLabel.mas_bottom).offset(30);
        make.left.mas_equalTo(label1);
    }];
    //维修配件头部
    labelMutabelArray = [[NSMutableArray alloc]initWithObjects:@"序号",@"配件代码",@"配件名称",@"数量",@"收费区分",@"销售单价",@"销售金额",@"折扣率",@"优惠金额",@"实收金额", nil];
    HJCommonTableHeaderView*repairPartHeaderView=[[HJCommonTableHeaderView alloc]init];
    repairPartHeaderView.titleAry=[labelMutabelArray copy];
    [self addSubview:repairPartHeaderView];
    [repairPartHeaderView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.height.right.mas_equalTo(projectHeaderView);
        make.top.mas_equalTo(label3.mas_bottom);
    }];
    UITableView*repairPartTableView=[[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
    repairPartTableView.delegate=self;
    repairPartTableView.dataSource=self;
    repairPartTableView.tableFooterView=[UIView new];
    repairPartTableView.layer.borderWidth=1;
    repairPartTableView.layer.borderColor=[UIColor grayColor].CGColor;
    repairPartTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    self.repairPartTableView=repairPartTableView;
    [contentView addSubview:repairPartTableView];
    [repairPartTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(repairPartHeaderView);
        make.top.mas_equalTo(repairPartHeaderView.mas_bottom);
        make.height.mas_equalTo(100);
    }];
    
    //维修配件合计
    UILabel*repairPartTotalLabel=[[UILabel alloc]init];
    [contentView addSubview:repairPartTotalLabel];
    repairPartTotalLabel.text=@"维修配件费合计:";
    self.repairPartTotalLabel=repairPartTotalLabel;
    [repairPartTotalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(label1);
        make.top.mas_equalTo(repairPartTableView.mas_bottom).offset(10);
    }];
    //优惠金额
    UILabel*repairDiscountLabel=[[UILabel alloc]init];
    [contentView addSubview:repairDiscountLabel];
    repairDiscountLabel.text=@"优惠金额:";
    self.repairDiscountLabel=repairDiscountLabel;
    [repairDiscountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(repairPartTableView);
        make.centerY.mas_equalTo(repairPartTotalLabel);
    }];
    
    //其他项目
    UILabel*label4=[[UILabel alloc]init];
    [contentView addSubview:label4];
    label4.font=[UIFont boldSystemFontOfSize:13];
    label4.text=@"其他项目结算";
    [label4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(repairDiscountLabel.mas_bottom).offset(30);
        make.left.mas_equalTo(label1);
    }];
    //其他项目头部
    labelMutabelArray = [[NSMutableArray alloc]initWithObjects:@"序号",@"项目代码",@"项目名称",@"附加项目费",@"折扣率",@"优惠金额",nil];
    HJCommonTableHeaderView*otherProjectHeaderView=[[HJCommonTableHeaderView alloc]init];
    otherProjectHeaderView.titleAry=[labelMutabelArray copy];
    [self addSubview:otherProjectHeaderView];
    [otherProjectHeaderView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.height.right.mas_equalTo(projectHeaderView);
        make.top.mas_equalTo(label4.mas_bottom);
    }];
    UITableView*otherProjectTableView=[[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
    otherProjectTableView.delegate=self;
    otherProjectTableView.dataSource=self;
    otherProjectTableView.tableFooterView=[UIView new];
    otherProjectTableView.layer.borderWidth=1;
    otherProjectTableView.layer.borderColor=[UIColor grayColor].CGColor;
    self.otherProjectTableView=otherProjectTableView;
    otherProjectTableView.separatorStyle=UITableViewCellSeparatorStyleNone;

    [contentView addSubview:otherProjectTableView];
    [otherProjectTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(repairPartHeaderView);
        make.top.mas_equalTo(otherProjectHeaderView.mas_bottom);
        make.height.mas_equalTo(100);
    }];

    //附加费合计
    UILabel*addTotalLabel=[[UILabel alloc]init];
    [contentView addSubview:addTotalLabel];
    addTotalLabel.text=@"附加费合计:";
    self.addTotalLabel=addTotalLabel;
    [addTotalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(label1);
        make.top.mas_equalTo(otherProjectTableView.mas_bottom).offset(10);
    }];
    //优惠金额
    UILabel*addDiscountLabel=[[UILabel alloc]init];
    [contentView addSubview:addDiscountLabel];
    addDiscountLabel.text=@"优惠金额:";
    self.addDiscountLabel=addDiscountLabel;
    [addDiscountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(projectTableView);
        make.centerY.mas_equalTo(addTotalLabel);
    }];
    
    //分割线
    UIView*line1=[[UIView alloc]init];
    [contentView addSubview:line1];
    line1.backgroundColor=[UIColor grayColor];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(projectTableView);
        make.top.mas_equalTo(addDiscountLabel.mas_bottom).offset(10);
        make.height.mas_equalTo(1);
    }];
    //三日电时间
    UILabel*thirdTimeLabel=[[UILabel alloc]init];
    [contentView addSubview:thirdTimeLabel];
    thirdTimeLabel.text=@"三日电访时间:";
    self.thirdTimeLabel=thirdTimeLabel;
    [thirdTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(label1);
        make.top.mas_equalTo(line1.mas_bottom).offset(10);
    }];
    
    //下次保养
    UILabel*nextTimeLabel=[[UILabel alloc]init];
    [contentView addSubview:nextTimeLabel];
    nextTimeLabel.text=@"下次保养时间:";
    self.nextTimeLabel=nextTimeLabel;
    [nextTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(thirdTimeLabel.mas_right).offset(10);
        make.size.mas_equalTo(thirdTimeLabel);
        make.centerY.mas_equalTo(thirdTimeLabel);
    }];
    //下次保养里程
    UILabel*nextMileageLabel=[[UILabel alloc]init];
    [contentView addSubview:nextMileageLabel];
    nextMileageLabel.text=@"下次保养里程:";
    self.nextMileageLabel=nextMileageLabel;
    [nextMileageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(nextTimeLabel.mas_right).offset(10);
        make.size.mas_equalTo(thirdTimeLabel);
        make.centerY.mas_equalTo(thirdTimeLabel);
        make.right.mas_equalTo(projectTableView);
    }];
    
    //不回访原因
    UILabel*resonLabel=[[UILabel alloc]init];
    [contentView addSubview:resonLabel];
    resonLabel.text=@"不回访原因:";
    self.resonLabel=resonLabel;
    [resonLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(projectTableView);
        make.top.mas_equalTo(nextMileageLabel.mas_bottom).offset(10);
    }];
    
    //备注
    UILabel*remarkLabel=[[UILabel alloc]init];
    [contentView addSubview:remarkLabel];
    remarkLabel.text=@"工单备注:";
    remarkLabel.layer.borderColor=[UIColor blackColor].CGColor;
    remarkLabel.layer.borderWidth=1;
    [remarkLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(projectTableView);
        make.top.mas_equalTo(resonLabel.mas_bottom).offset(10);
        make.height.mas_equalTo(35);
    }];
    
    //分割线
    UIView*line2=[[UIView alloc]init];
    [contentView addSubview:line2];
    line2.backgroundColor=[UIColor grayColor];
    [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(projectTableView);
        make.top.mas_equalTo(remarkLabel.mas_bottom).offset(5);
        make.height.mas_equalTo(1);
    }];
    
    //费用合计
    UILabel*costTotalLabel=[[UILabel alloc]init];
    [contentView addSubview:costTotalLabel];
    costTotalLabel.text=@"费用合计:";
    self.costTotalLabel=costTotalLabel;
    [costTotalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(thirdTimeLabel);
        make.size.mas_equalTo(thirdTimeLabel);
        make.top.mas_equalTo(line2.mas_bottom).offset(10);
    }];
    //优惠合计
    UILabel*discountTotalLabel=[[UILabel alloc]init];
    [contentView addSubview:discountTotalLabel];
    discountTotalLabel.text=@"优惠合计:";
    self.discountTotalLabel=discountTotalLabel;
    [discountTotalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(nextTimeLabel);
        make.centerY.mas_equalTo(costTotalLabel);
        make.size.mas_equalTo(nextTimeLabel);
    }];
    //圆整金额
    UILabel*yuanzhengLabel=[[UILabel alloc]init];
    [contentView addSubview:yuanzhengLabel];
    yuanzhengLabel.text=@"圆整金额:";
    self.yuanzhengLabel=yuanzhengLabel;
    [yuanzhengLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(nextMileageLabel);
         make.centerY.mas_equalTo(costTotalLabel);
         make.size.mas_equalTo(nextMileageLabel);
    }];
    
    //减免金额
    UILabel*jianMianPriceLabel=[[UILabel alloc]init];
    [contentView addSubview:jianMianPriceLabel];
    jianMianPriceLabel.text=@"减免金额:";
    self.jianMianPriceLabel=jianMianPriceLabel;
    [jianMianPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(nextTimeLabel);
        make.top.mas_equalTo(discountTotalLabel.mas_bottom).offset(10);
        make.size.mas_equalTo(nextTimeLabel);
    }];
    
    //去零金额
    UILabel*qulingPriceLabel=[[UILabel alloc]init];
    [contentView addSubview:qulingPriceLabel];
    qulingPriceLabel.text=@"去零金额:";
    self.qulingPriceLabel=qulingPriceLabel;
    [qulingPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(nextMileageLabel);
        make.centerY.mas_equalTo(jianMianPriceLabel);
        make.size.mas_equalTo(nextMileageLabel);
    }];
    
    //分割线
    UIView*line3=[[UIView alloc]init];
    [contentView addSubview:line3];
    line3.backgroundColor=[UIColor grayColor];
    [line3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(projectTableView);
        make.top.mas_equalTo(qulingPriceLabel.mas_bottom).offset(5);
        make.height.mas_equalTo(1);
    }];
    
    //总计
    UILabel*totalLabel=[[UILabel alloc]init];
    totalLabel.text=@"总计:";
    [contentView addSubview:totalLabel];
    [totalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(label1);
        make.top.mas_equalTo(line3.mas_bottom).offset(10);
    }];
//
    //人民币大写
    UILabel*daxieLabel=[[UILabel alloc]init];
    daxieLabel.text=@"人民币大写:";
    [contentView addSubview:daxieLabel];
    [daxieLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(totalLabel.mas_right).offset(5);
        make.centerY.mas_equalTo(totalLabel);
    }];

    //应收金额
    UILabel*availPriceLabel=[[UILabel alloc]init];
    [contentView addSubview:availPriceLabel];
    availPriceLabel.text=@"应收总金额:";
    self.availPriceLabel=availPriceLabel;
    [availPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
      make.centerY.mas_equalTo(totalLabel);
     make.right.left.mas_equalTo(qulingPriceLabel);
    }];
//
    //分割线
    UIView*line4=[[UIView alloc]init];
    [contentView addSubview:line4];
    line4.backgroundColor=[UIColor grayColor];
    [line4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(line3);
        make.top.mas_equalTo(availPriceLabel.mas_bottom).offset(10);
        make.height.mas_equalTo(1);
    }];
    //备注
    UILabel*remarkLabel2=[[UILabel alloc]init];
    [contentView addSubview:remarkLabel2];
    remarkLabel2.text=@"备注:";
    self.remarkLabel2=remarkLabel2;
    [remarkLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(label1);
        make.top.mas_equalTo(line4.mas_bottom).offset(10);
    }];
//
    //分割线
    UIView*line5=[[UIView alloc]init];
    [contentView addSubview:line5];
    line5.backgroundColor=[UIColor grayColor];
    [line5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(projectTableView);
        make.top.mas_equalTo(remarkLabel2.mas_bottom).offset(10);
        make.height.mas_equalTo(1);
    }];
    
    //服务顾问签字
    UILabel*serviceAdvicerWriteLabel=[[UILabel alloc]init];
    [contentView addSubview:serviceAdvicerWriteLabel];
    serviceAdvicerWriteLabel.text=@"服务顾问签字:";
    [serviceAdvicerWriteLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(totalLabel);
        make.top.mas_equalTo(line5.mas_bottom).offset(10);
    }];
    
    //客户签字
    UILabel*customerWriteLabel=[[UILabel alloc]init];
    [contentView addSubview:customerWriteLabel];
    customerWriteLabel.text=@"客户签字:";
    [customerWriteLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(jianMianPriceLabel);
        make.centerY.mas_equalTo(serviceAdvicerWriteLabel);
    }];
    
    //日期
    UILabel*dateLabel=[[UILabel alloc]init];
    [contentView addSubview:dateLabel];
    dateLabel.text=@"日期:";
    [dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(qulingPriceLabel);
        make.centerY.mas_equalTo(serviceAdvicerWriteLabel);
    }];
    
    //服务热线
    UILabel*servicePhoneLabel=[[UILabel alloc]init];
    [contentView addSubview:servicePhoneLabel];
    servicePhoneLabel.text=@"服务热线:";
    self.servicePhoneLabel=servicePhoneLabel;
    [servicePhoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(serviceAdvicerWriteLabel);
        make.top.mas_equalTo(serviceAdvicerWriteLabel.mas_bottom).offset(80);
    }];
    
    //公司
    UILabel*companyLabel=[[UILabel alloc]init];
    companyLabel.text=@"承修单位:";
    self.companyLabel=companyLabel;
    companyLabel.numberOfLines=0;
    [contentView addSubview:companyLabel];
    [companyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(jianMianPriceLabel);
        make.centerY.mas_equalTo(servicePhoneLabel);
    }];
    
    //地址
    UILabel*addressLabel=[[UILabel alloc]init];
    [contentView addSubview:addressLabel];
    addressLabel.text=@"地址:";
    self.addressLabel=addressLabel;
    addressLabel.numberOfLines=0;
    [addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(qulingPriceLabel);
        make.centerY.mas_equalTo(servicePhoneLabel);
    }];
    [self layoutIfNeeded];
    contentView.frame=CGRectMake(0, 0, scrollView.mj_w, CGRectGetMaxY(addressLabel.frame)+100);
    scrollView.contentSize=contentView.bounds.size;
    
}
//-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
//{
//    [self removeFromSuperview];
//}
-(void)setRepairSettlementModel:(HJRepairSettlementModel *)repairSettlementModel
{
    _repairSettlementModel=repairSettlementModel;
    HJRepairSettlementTT_RepairOrderItemModel*repairSettlementTT_RepairOrderItemModel=repairSettlementModel.TT_REPAIR_ORDER_ITEM[0];
    HJRepairSettlementMAINTENANCE_STATEMENTModel*repairSettlementMAINTENANCE_STATEMENTModel=repairSettlementModel.MAINTENANCE_STATEMENT[0];
    NSString*str=[self.numberLabel.text stringByAppendingString:repairSettlementTT_RepairOrderItemModel.RO_NO.length?repairSettlementTT_RepairOrderItemModel.RO_NO:@""];
    self.numberLabel.text=str;
   // 结算日期
    self.settlementTimeLabel.text=[self.settlementTimeLabel.text stringByAppendingString:repairSettlementMAINTENANCE_STATEMENTModel.BALANCE_TIME?repairSettlementMAINTENANCE_STATEMENTModel.BALANCE_TIME:@""];
    NSString*repairType=self.repairTypeLabel.text;
    NSString*code=self.repairTypeCodeDict[repairSettlementMAINTENANCE_STATEMENTModel.REPAIR_TYPE_CODE];
    if (code) {
        repairType=[repairType stringByAppendingString:code];
    }
    //维修类型
    self.repairTypeLabel.text=repairType;
    
    //送修人
    self.sendRepairLabel.text=[self.sendRepairLabel.text stringByAppendingString:repairSettlementTT_RepairOrderItemModel.DELIVERER.length?repairSettlementTT_RepairOrderItemModel.DELIVERER:@""];
   //送修人电话
    self.sendRepairPhoneLabel.text=[self.sendRepairPhoneLabel.text stringByAppendingString:repairSettlementMAINTENANCE_STATEMENTModel.DELIVERER_MOBILE.length?repairSettlementMAINTENANCE_STATEMENTModel.DELIVERER_MOBILE:@""];
    
    //服务顾问
    self.serviceAdviserLabel.text=[self.serviceAdviserLabel.text stringByAppendingString:repairSettlementTT_RepairOrderItemModel.DELIVERER.length?repairSettlementTT_RepairOrderItemModel.DELIVERER:@""];
    //出厂里程
    self.mileageLabel.text=[self.mileageLabel.text stringByAppendingString:repairSettlementTT_RepairOrderItemModel.TOTAL_MILEAGE.length?repairSettlementTT_RepairOrderItemModel.TOTAL_MILEAGE:@""];
    //vin
    self.vinLabel.text=[self.vinLabel.text stringByAppendingString:repairSettlementTT_RepairOrderItemModel.VIN.length?repairSettlementTT_RepairOrderItemModel.VIN:@""];
    
    //车牌号
    self.carNumberLabel.text=[self.carNumberLabel.text stringByAppendingString:repairSettlementTT_RepairOrderItemModel.PLATE_NUMBER.length?repairSettlementTT_RepairOrderItemModel.PLATE_NUMBER:@""];
    //车型
    self.carTypeLabel.text=[self.carTypeLabel.text stringByAppendingString:repairSettlementTT_RepairOrderItemModel.MODEL.length?repairSettlementTT_RepairOrderItemModel.MODEL:@""];
    // 维修技师
    self.repairTechLabel.text=[self.repairTechLabel.text stringByAppendingString:repairSettlementMAINTENANCE_STATEMENTModel.CHIEF_TECHNICIAN.length?repairSettlementMAINTENANCE_STATEMENTModel.CHIEF_TECHNICIAN:@""];
    //开工单时间
    self.placeOrderLabel.text=[self.placeOrderLabel.text stringByAppendingString:repairSettlementMAINTENANCE_STATEMENTModel.RO_CREATE_DATE.length?repairSettlementMAINTENANCE_STATEMENTModel.RO_CREATE_DATE:@""];
    //竣工时间
    self.completedTimeLabel.text=[self.completedTimeLabel.text stringByAppendingString:repairSettlementMAINTENANCE_STATEMENTModel.COMPLETE_TIME.length?repairSettlementMAINTENANCE_STATEMENTModel.COMPLETE_TIME:@""];
   
    //工时费合计
    self.projectTotalLabel.text=[self.projectTotalLabel.text stringByAppendingString:repairSettlementModel.LABOUR_AMOUNT.length?repairSettlementModel.LABOUR_AMOUNT:@""];
   
   //维修项目工程优惠
    self.projectDiscountLabel.text=[self.projectDiscountLabel.text stringByAppendingString:repairSettlementModel.XM_DISCOUNT_AMOUNT.length?repairSettlementModel.XM_DISCOUNT_AMOUNT:@""];
    //维修配件费合计
    self.repairPartTotalLabel.text=[self.repairPartTotalLabel.text stringByAppendingString:repairSettlementModel.PART_AMOUNT.length?repairSettlementModel.PART_AMOUNT:@""];
   //维修配件优惠
    self.repairDiscountLabel.text=[self.repairDiscountLabel.text stringByAppendingString:repairSettlementModel.PJ_DISCOUNT_AMOUNT.length?repairSettlementModel.PJ_DISCOUNT_AMOUNT:@""];
   
    // 附加费合计
    self.addTotalLabel.text=[self.addTotalLabel.text stringByAppendingString:repairSettlementModel.ADDITEMA_AMOUNT.length?repairSettlementModel.ADDITEMA_AMOUNT:@""];
   //附加费优惠卷
    self.addDiscountLabel.text=[self.addDiscountLabel.text stringByAppendingString:repairSettlementModel.FJ_DISCOUNT_AMOUNT?repairSettlementModel.FJ_DISCOUNT_AMOUNT:@""];
    
    //费用合计
    self.costTotalLabel.text=[self.addDiscountLabel.text stringByAppendingString:repairSettlementModel.ALL_AMOUNT.length?repairSettlementModel.ALL_AMOUNT:@""];
//    //优惠合计
    self.discountTotalLabel.text=[self.discountTotalLabel.text stringByAppendingString:repairSettlementModel.DISCOUNT_AMOUNT.length?repairSettlementModel.DISCOUNT_AMOUNT:@""];
//    //圆整金额
//
//    self.yuanzhengLabel.text=[self.discountTotalLabel.text stringByAppendingString:repairSettlementModel.ALL_AMOUNT];
    
    //减免金额
    self.jianMianPriceLabel.text=[self.jianMianPriceLabel.text stringByAppendingString:repairSettlementModel.REDUCTION.length?repairSettlementModel.REDUCTION:@""];
   
    //去零金额
    self.qulingPriceLabel.text=[self.qulingPriceLabel.text stringByAppendingString:repairSettlementModel.DISCOUNTZERO.length?repairSettlementModel.DISCOUNTZERO:@""];
    //应收总金额
    self.availPriceLabel.text=[self.availPriceLabel.text stringByAppendingString:repairSettlementModel.ALL_AMOUNT.length?repairSettlementModel.ALL_AMOUNT:@""];
   
    self.resonLabel.text=[self.resonLabel.text stringByAppendingString:repairSettlementMAINTENANCE_STATEMENTModel.REMARK?repairSettlementMAINTENANCE_STATEMENTModel.REMARK:@""];
//    //备注
    self.remarkLabel2.text=[self.remarkLabel2.text stringByAppendingString:repairSettlementMAINTENANCE_STATEMENTModel.RO_TROUBLE_DESC?repairSettlementMAINTENANCE_STATEMENTModel.RO_TROUBLE_DESC:@""];
    
//    //服务热线
    self.servicePhoneLabel.text=[self.servicePhoneLabel.text stringByAppendingString:repairSettlementMAINTENANCE_STATEMENTModel.HOT_LINE?repairSettlementMAINTENANCE_STATEMENTModel.HOT_LINE:@""];
    
//    //承修单位
    self.companyLabel.text=[self.companyLabel.text stringByAppendingString:repairSettlementMAINTENANCE_STATEMENTModel.ASC_NAME?repairSettlementMAINTENANCE_STATEMENTModel.ASC_NAME:@""];
    self.titleLabel.text=repairSettlementMAINTENANCE_STATEMENTModel.ASC_NAME;
   
//    //地址
    self.addressLabel.text=[self.addressLabel.text stringByAppendingString:repairSettlementMAINTENANCE_STATEMENTModel.ADDRESS?repairSettlementMAINTENANCE_STATEMENTModel.ADDRESS:@""];
//
    
    CGFloat projectTableViewH=self.repairSettlementModel.LABOURLIST.count*60;
        [self.projectTableView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(projectTableViewH);
        }];
     CGFloat repairPartTableViewH=self.repairSettlementModel.PARTLIST.count*60;
        [self.repairPartTableView mas_updateConstraints:^(MASConstraintMaker *make) {
             make.height.mas_equalTo(repairPartTableViewH);
        }];
    
    CGFloat otherProjectTableViewH=self.repairSettlementModel.PARTLIST.count*60;
        [self.otherProjectTableView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(otherProjectTableViewH);
        }];
    [self.projectTableView reloadData];
    [self.repairPartTableView reloadData];
    [self.otherProjectTableView reloadData];
    
    [self layoutIfNeeded];
    self.contentView.frame=CGRectMake(0, 0, self.scrollView.mj_w, CGRectGetMaxY(self.addressLabel.frame)+100);
    self.scrollView.contentSize=self.contentView.bounds.size;
}
#pragma mark --UITableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView==self.projectTableView) {
        return self.repairSettlementModel.LABOURLIST.count;
    }else if (tableView==self.repairPartTableView){
        return self.repairSettlementModel.PARTLIST.count;
    }else if (tableView==self.otherProjectTableView){
        return self.repairSettlementModel.ADDITEM.count;
    }
    return 0;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==self.projectTableView) {
        HJSettlementRepairProjectViewCell*cell=[HJSettlementRepairProjectViewCell cellWithTable:tableView];
        cell.repairSettlementLabourListModel=self.repairSettlementModel.LABOURLIST[indexPath.row];
        cell.indePath=indexPath;
        return cell;
    }else if (tableView==self.repairPartTableView){
        HJSettlementRepairPartsViewCell*cell=[HJSettlementRepairPartsViewCell cellWithTable:tableView];
        cell.repairSettlementPairListModel=self.repairSettlementModel.PARTLIST[indexPath.row];
        cell.indePath=indexPath;
        return cell;
    }else if (tableView==self.otherProjectTableView){
        HJSettlementAdditionalItemsViewCell*cell=[HJSettlementAdditionalItemsViewCell cellWithTable:tableView];
        cell.repairSettlementAdditemModel=self.repairSettlementModel.ADDITEM[indexPath.row];
        cell.indePath=indexPath;
        return cell;
    }
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}
@end
